package com.hailiang.ing;


import sun.misc.Regexp;

import javax.servlet.*;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MyFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init...");
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        String uname = req.getParameter("username");
        String pword = req.getParameter("password");
        String emal = req.getParameter("emal");


        String reg = "^\\w{6,12}$";
        String ema = "^([a-z0-9_A-Z]+[-|\\.]?)+[a-z0-9_A-Z]@([a-z0-9_A-Z]+(-[a-z0-9_A-Z]+)?\\.)+[a-zA-Z_]{2,}$";
        Pattern compile = Pattern.compile(reg);


        Matcher matcher = compile.matcher(uname);
        Matcher matcher1 = compile.matcher(pword);
        boolean c = Pattern.compile(ema).matcher(emal).find();

        boolean b = matcher1.find();
        boolean a = matcher.find();
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        if(a==true && b==true &&c==true){
            chain.doFilter(req,resp);
        }

        System.out.println("do...");
        resp.getWriter().print("no1");

    }

    @Override
    public void destroy() {

    }
}
